//
//  RegisterSecondViewController.swift
//  ezyform
//
//  Created by MoennigQ on 8/9/20.
//  Copyright © 2020 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import MBProgressHUD
class RegisterSecondViewController: BaseViewController {
    let customView = RegisterSecondView(customBackToPreFlag: true)
    var model: RegisterModel!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initUI()
        //如果设置过数据，back to第一步后，再进入第二步，要显示原来设置的数据
        self.customView.setData(self.model.physicalAndPOBoxAddressViewModel)
    }
    
    func initUI(){
        self.view = self.customView
        self.customView.setTitleInfo(R.string.localizable.register())
        self.customView.submitBtn.addTarget(self, action: #selector(submitBtnClick), for: UIControl.Event.touchUpInside)
    }
    
    @objc
    func submitBtnClick(){
        let vm = RegisterService()
        vm.setBlockAfterNetwork({ (result , _) -> Void in
            ModelViewUtil.shared.hideLoadingView()
            let vc = RegisterSuccessViewController()
            self.navigationController?.pushViewController(vc, animated: false)
        }) {(code,msg) -> Void in
            ModelViewUtil.shared.hideLoadingView()
            Tool().showErrorInfo(code,msg)
        }
        //add Loading view
        ModelViewUtil.shared.showLoadingView("Submitting...")
        vm.submitRegisterInfo(self.model)
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(true, animated: true)
    }
}
